package com.chd.ledger_server.service.impl;

import com.chd.ledger_server.entity.PipeWarning;
import com.chd.ledger_server.dao.PipeWarningDao;
import com.chd.ledger_server.service.PipeWarningService;
import com.chd.ledger_server.domain.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 管材预警管理表(PipeWarning)表服务实现类
 *
 * @author makejava
 * @since 2025-07-06 05:58:49
 */
@Service("pipeWarningService")
public class PipeWarningServiceImpl implements PipeWarningService {
    @Resource
    private PipeWarningDao pipeWarningDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pipeWarId 主键
     * @return 实例对象
     */
    @Override
    public PipeWarning queryById(Integer pipeWarId) {
        return this.pipeWarningDao.queryById(pipeWarId);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo queryAllPipeWarningsByPage(PageDto pageDto) {
        //空值处理
        if (pageDto.getPage() == null || pageDto.getSize() == null) {
            pageDto.setPage(1);
            pageDto.setSize(10);
        }
        PageHelper.startPage(pageDto.getPage(), pageDto.getSize());
        List<PipeWarning> list = pipeWarningDao.queryAll(pageDto.getPipeWarning());
        PageInfo<PipeWarning> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param pipeWarning 实例对象
     * @return 实例对象
     */
    @Override
    public PipeWarning insert(PipeWarning pipeWarning) {
        this.pipeWarningDao.insert(pipeWarning);
        return pipeWarning;
    }

    /**
     * 修改数据
     *
     * @param pipeWarning 实例对象
     * @return 实例对象
     */
    @Override
    public PipeWarning update(PipeWarning pipeWarning) {
        this.pipeWarningDao.update(pipeWarning);
        return this.queryById(pipeWarning.getPipeWarId());
    }

    /**
     * 通过主键删除数据
     *
     * @param pipeWarId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pipeWarId) {
        return this.pipeWarningDao.deleteById(pipeWarId) > 0;
    }
}
